import Vue from 'vue'
import Router from "vue-router";
Vue.use(Router);
import Caidan from "../Pages/Caidan.vue";
import Shopping from "../Pages/Shopping.vue";
import Waisong from "../components/waisong.vue";
import City from "../components/city.vue";
import Details from "../Pages/Details.vue";
import Skip from "../Pages/Skip.vue";
import Master from "../Pages/Master";
import Goods from "../Pages/Goods"
import Member from "../Pages/Member"
import PingLun from "../Pages/PingLun"
import Chaopin from "../Pages/Chaopin.vue";
import Chaowan from "../Pages/Chaowan.vue";
import Xinpin from "../Pages/Xinpin.vue";
import Youhui from "../Pages/Yhuiquan.vue";
import Failure from "../components/failure.vue";
import Dizhi from "../Pages/Dizhi.vue";
import Goods2 from "../Pages/Goods2"
let routes = [
    {
        path:'/Caidan',
        component:Caidan
    },
    {
      path:'/Goods2/:goodid',
      component:Goods2
  },
    {
        path:'/Waisong',
        component:Waisong,
    },
    {
        path:'/City',
        component:City,
    },
    {
        path:'/Shopping',
        component:Shopping
    },
    {
        path:'/Details/:xiaoid',
        component:Details
    },
    {
        path:'/Skip',
        component:Skip
    },
    {
      path:'/Dizhi',
      component:Dizhi
    },
    {
        path: '/',  //默认页
        redirect:'/Master' //配置型跳转
    },
    {
        path: '/',  //默认页
        component:Master //配置型跳转
    },
    {
        path:"/Master",
        component:Master
    },
    {
        path:"/Goods/:shopid",
        component:Goods
    },
    {
        path:"/Goods",
        component:Goods
    },
    {
        path:"/Member",
        component:Member
    },
    {
        path:"/PingLun",
        component:PingLun
    },
    {
        path: '/Chaopin',
        component: Chaopin
    },
    {
        path: '/Xinpin',
        component: Xinpin
    },
    {
        path: '/Chaowan',
        component: Chaowan
    },
    {
        path: '/Youhui',
        component: Youhui
    },
    {
      path: '/PingLun',
      component: PingLun
  },

    //我的
    {
        path: "/my",
        name: "My",
        component: () => import("../views/lsc/My.vue"),
      },
      {
        path: "/profile",
        name: "Profile",
        
        component: () =>
          import( "../views/lsc/Profile.vue"),
      },
     
      {
        path: "/login",
        name: "Login",
        component: () => import("../views/lsc/Login.vue"),
      },
      {
        path: "/address",
        name: "Address",
        component: () => import("../views/lsc/Address.vue"),
      },
      {
        path: "/add",
        name: "Add",
        component: () => import("../views/lsc/Add.vue"),
      },
      {
        path: "/amend",
        name: "Amend",
        component: () => import("../views/lsc/Amend.vue"),
      },
      {
        path: "/join",
        name: "Join",
        component: () => import("../views/lsc/Join.vue"),
      },
      {
        path: "/service",
        name: "Service",
        component: () => import("../views/lsc/Service.vue"),
      },  
      {
        path: "/invoice",
        name: "Invoice",
        component: () => import("../views/lsc/Invoice.vue"),
      }, 
      {
        path: "/balance",
        name: "Balance",
        component: () => import("../views/lsc/Balance.vue"),
      },
      {
        path: "/code",
        name: "Code",
        component: () => import("../views/lsc/Code.vue"),
      },
      {
        path: "/detail",
        name: "Detail",
        component: () => import("../views/lsc/Detail.vue"),
      },
      {
        path: "/gift",
        name: "Gift",
        component: () => import("../views/lsc/Gift.vue"),
      },
      {
        path: "/coupons",
        name: "Coupons",
        component: () => import("../views/lsc/Coupons.vue"),
      },
      {
        path: "/order",
        name: "Order",
        component: () => import("../views/lsc/Order.vue"),
      }
      ,{
        path: "/wallet",
        name: "Wallet",
        component: () => import("../views/lsc/Wallet.vue"),
      }
      ,{
        path: "/shopp/:id",
        name: "Shopp",
        component: () => import("../views/lsc/Shopp.vue"),
      },
      {
        path: '*',
        component: Failure
      }
]
let router = new Router({
    routes,
})
// 路由前置守卫
// router.beforeEach((to,from,next)=>{
//     console.log('to',to);
//     console.log('from',from);
//     console.log('next',next);
//     if(to.path.startsWith("/Shopping")){
//         console.log('你去的是',to.path);
//         if(localStorage.getItem("username")){
//             next()
//         }else{
//             next({path:'/Loginner',query:{toPath:to.path}})
//         }
//     }
//     next()
// })
export default router

router.beforeEach((to, from, next) => {
 
    if(to.path.startsWith('/order') || to.path==='/balance' ){    
      if(localStorage.getItem("userName")){
        next();
     }else{
        next({path:"/login",query:{toPath:to.path}});
     }
       
    }
    next()
  })